﻿Imports System.Text.RegularExpressions
Imports Microsoft.Office.Interop
Imports System.Data

'TextBox[]TextBoxlist = new TextBox[5]


Class MainWindow
    Private TextBoxArray As New List(Of TextBox)
    Dim DataBuff(12) As String

    Dim xlApp As Excel.Application  'Application 对象是 Excel 对象模型中最高层级的对象，代表Excel应用程序本身，也包含组成工作薄的许多部分，包括工作薄、工作表、单元格集合以及它们包含的数据。
    Dim xlBook As Excel.Workbook    '设置 xlBook 为一个工作薄
    Dim xlSheet As Excel.Worksheet  '设置 xlSheet 为一个工作薄的工作表
    Dim DataArray(2000, 2000) As Integer



    '**********************************按钮添加函数
    Sub AddButton()
        Dim MyButton(0 To 98) As Button
        Dim II As Integer
        For II = 0 To 98
            MyButton(II) = New Button
            MyButton(II).Name = "Abc " & II
            'MyButton(II).Location = New Point(II * 5, II * 5)
            ''位置自行确定/绑定事件 
            AddHandler MyButton(II).Click, AddressOf DoIt
            'Me.Controls.Add(MyButton(II))
        Next
    End Sub
    Sub DoIt(ByVal sender As Object, ByVal e As System.EventArgs)
        '执行变色()
    End Sub

    '自定义函数
    '文本框默认输入为数字
    Private Function DefaultBeNum(ByVal TextBox As String) As String
        If IsNumeric(TextBox) Then
        Else
            TextBox = "0"
        End If
        DefaultBeNum = TextBox
    End Function

    Private Function find(ByVal a() As String, ByVal x As String) As Integer
        Dim n%, p%
        n = UBound(a) '数组元素个数
        For p = 1 To n
            If x = a(p) Then Exit For '如果找到相同 则退出循环 此时的P值既是结果
        Next p
        '如果没找到 P值将会是 N+1
        If p > n Then p = 0
        find = p
    End Function

    Private Sub Window_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded

        DataInCount()
        ButtonDataInDefault_Click()
        TextBoxArray.AddRange({ _
            Me.TextBoxList01, Me.TextBoxList02, Me.TextBoxList03, Me.TextBoxList04, _
            Me.TextBoxList05, Me.TextBoxList06, Me.TextBoxList07, Me.TextBoxList08, _
            Me.TextBoxList11, Me.TextBoxList12, Me.TextBoxList13, Me.TextBoxList14, _
            Me.TextBoxList15, Me.TextBoxList16, Me.TextBoxList17, Me.TextBoxList18, _
            Me.TextBoxList21, Me.TextBoxList22, Me.TextBoxList23, Me.TextBoxList24, _
            Me.TextBoxList25, Me.TextBoxList26, Me.TextBoxList27, Me.TextBoxList28, _
            Me.TextBoxList31, Me.TextBoxList32, Me.TextBoxList33, Me.TextBoxList34, _
            Me.TextBoxList35, Me.TextBoxList36, Me.TextBoxList37, Me.TextBoxList38, _
            Me.TextBoxList41, Me.TextBoxList42, Me.TextBoxList43, Me.TextBoxList44, _
            Me.TextBoxList45, Me.TextBoxList46, Me.TextBoxList47, Me.TextBoxList48, _
            Me.TextBoxList51, Me.TextBoxList52, Me.TextBoxList53, Me.TextBoxList54, _
            Me.TextBoxList55, Me.TextBoxList56, Me.TextBoxList57, Me.TextBoxList58, _
            Me.TextBoxList61, Me.TextBoxList62, Me.TextBoxList63, Me.TextBoxList64, _
            Me.TextBoxList65, Me.TextBoxList66, Me.TextBoxList67, Me.TextBoxList68, _
            Me.TextBoxList71, Me.TextBoxList72, Me.TextBoxList73, Me.TextBoxList74, _
            Me.TextBoxList75, Me.TextBoxList76, Me.TextBoxList77, Me.TextBoxList78})
        For Each btn As TextBox In TextBoxArray
            AddHandler btn.MouseMove, AddressOf Me.TextBoxClick
        Next

        For Each btn As TextBox In TextBoxArray
            AddHandler btn.MouseLeave, AddressOf Me.TextBoxLeave
        Next
    End Sub



    Private Sub TextBoxIn_TextChanged(ByVal sender As System.Object, ByVal e As System.Windows.Controls.TextChangedEventArgs) Handles TextBoxIn.TextChanged
        '状态栏1更新
        DataInCount()
    End Sub

    '鼠标移动到文本框时的动作函数
    Private Sub TextBoxClick(ByVal sender As Object, ByVal e As MouseEventArgs)
        Dim l As TextBox = sender
        '状态栏2更新
        TextBoxNumCount("当前点击的文本框序号是：" + Str(TextBoxArray.IndexOf(sender)))
    End Sub

    '鼠标离开文本框时的动作函数
    Private Sub TextBoxLeave(ByVal sender As Object, ByVal e As MouseEventArgs)
        '状态栏2更新
        TextBoxNumCount("")
    End Sub

    '状态栏1更新
    Private Function DataInCount() As Integer
        TextBlockDataCnt.Text = "输入区数据统计：" + Str(Len(TextBoxIn.Text))
        DataInCount = 0
    End Function

    '状态栏2更新
    Private Function TextBoxNumCount(ByVal Index As String) As Integer
        TextBlockNumCnt.Text = Index
        TextBoxNumCount = 0
    End Function


    Private Sub ButtonDataInDefault_Click() Handles ButtonDataInDefault.Click
        TextBoxIn.Text = "订单编号：351514924897867  成交时间：2013-05-22 12:52 深圳华强北... "
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + ""
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "金电子感光板专用显影粉(感光板显影剂)"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + " "
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "1.00	5	"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "申请售后"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "投诉卖家"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "201.50"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "(含快递:8.00 )"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "交易成功"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "订单详情"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "查看物流"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "双方已评"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "追加评论"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "删除"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "备忘"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "分享"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "转卖"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + ""
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "双面过孔解决方案 4合1套装 铆钉 鸡眼 金属化孔500颗"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + " "
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "20.00	1	"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "申请售后"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "投诉卖家"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "转卖"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + ""
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "1.6厚度 特价 金电子 正性 电木单面感光板10*15cm PP1015"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + " "
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "7.50	5	"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "申请售后"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "投诉卖家"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "转卖"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + ""
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "超级迷你电钻组合 进口电机 含电源等 PCB线路板打孔首选"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + " "
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "40.00	1	"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "申请售后"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "投诉卖家"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "转卖"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + ""
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "批发 感光干膜 代替热转印制作PCB板 蚀刻片用 感光膜"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + " "
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "0.50	20	"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "申请售后"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "投诉卖家"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "转卖"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + ""
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "喷墨打印菲林+激光打印胶片二合一菲林 PCB制版首选"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + " "
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "1.00	25	"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "申请售后"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "投诉卖家"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "转卖"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + ""
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "批发 感光干膜用脱膜剂 20克一包"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + " "
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "1.00	20	"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "申请售后"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "投诉卖家"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "转卖"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + ""
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "电路板腐蚀剂 PCB蚀刻剂 黄色固体 500克一瓶 三氯化学纯"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + " "
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "18.00	2	"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "申请售后"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "投诉卖家"
        TextBoxIn.Text = TextBoxIn.Text + Chr(13) + Chr(10) + "转卖"
        DataInCount()
    End Sub

    Private Sub button15_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles button15.Click
        If IsNumeric(TextBoxNum.Text) Then
            MsgBox(TextBoxIn.Text(Int(TextBoxNum.Text)))
        Else
            TextBoxNum.Text = "0"
        End If
    End Sub

    Private Sub TextBoxNum_TextChanged(ByVal sender As System.Object, ByVal e As System.Windows.Controls.TextChangedEventArgs) Handles TextBoxNum.TextChanged
        TextBoxNum.Text = DefaultBeNum(TextBoxNum.Text)
    End Sub

    Private Sub ButtonChangeClear_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles ButtonChangeClear.Click
        TextBoxIn.Text = ""
        TextBoxOut.Text = ""
    End Sub

    Private Function TextBoxArrayClear() As Integer
        For Each btn As TextBox In TextBoxArray
            btn.Text = ""
        Next
        TextBoxArrayClear = 0
    End Function



    Private Sub ButtonChangeAll_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles ButtonChangeAll.Click
        Dim TargetOldFlag(12) As String
        Dim DeleteFlag(12) As String
        Dim TargetLen(12) As Integer
        Dim TextBuffdText As String
        Dim TextSubdText As String
        Dim TextStr(1024) As String

        TargetOldFlag(1) = "订单编号："                                  'OK
        TargetOldFlag(2) = "  成交时间："                                'OK
        TargetOldFlag(3) = "  成交时间："                                'OK

        TargetOldFlag(4) = Chr(13) + Chr(10) + Chr(13) + Chr(10)         'OK
        TargetOldFlag(5) = Chr(13) + Chr(10)   'OK
        TargetOldFlag(6) = Chr(9)                                        'OK
        TargetOldFlag(7) = Chr(9)

        TargetOldFlag(8) = Chr(13) + Chr(10) + "(含快递:"                'OK
        TargetOldFlag(9) = Chr(13) + Chr(10) + "保险:"                   'OK
        TargetOldFlag(10) = ")"

        TargetOldFlag(11) = Chr(13) + Chr(10)

        DeleteFlag(0) = TargetOldFlag(4)
        DeleteFlag(1) = "转卖" + Chr(13) + Chr(10) + Chr(13) + Chr(10)

        TargetLen(1) = 0
        TargetLen(2) = 16
        TargetLen(3) = 0
        TargetLen(4) = 0
        TargetLen(5) = 0
        TargetLen(6) = 0
        TargetLen(7) = 0
        TargetLen(8) = 0
        TargetLen(9) = 0

        DataBuff(1) = ""
        DataBuff(2) = ""
        DataBuff(3) = ""
        DataBuff(4) = ""
        DataBuff(5) = ""
        DataBuff(6) = ""
        DataBuff(7) = ""
        DataBuff(8) = ""
        DataBuff(9) = ""

        TextBoxArrayClear()
        TextBuffdText = TextBoxIn.Text
        Dim StrA(15) As String
        Dim ALen(15) As Integer
        Dim StrZ(15) As String
        Dim ZLen(15) As Integer
        Dim StrLen(15) As String
        For i = 1 To 15
            StrA(i) = ""
            StrZ(i) = ""
            StrLen(i) = ""
        Next
        For i = 1 To 15
            ALen(15) = 0
            ZLen(15) = 0
        Next



        '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        '1.搜索(订单编号、成交时间、卖家名称信息)
        '1.1首先，提取（订单编号、成交时间、卖家名称信息）
        '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        For i = 1 To 3
            StrA(i) = TargetOldFlag(i)                                  '开始字符StrA(i)
            If StrA(i) = StrA(i - 1) Then
                ALen(i) = InStr(TextBuffdText, StrA(i)) + StrLen(i - 1) '开始位置ALen(i)+继承StrLen(i-1)
            Else
                ALen(i) = InStr(TextBuffdText, StrA(i))                 '开始位置ALen(i)
            End If

            StrZ(i) = TargetOldFlag(i + 1)                              '结束字符StrZ(i)
            ZLen(i) = InStr(TextBuffdText, StrZ(i))                     '结束位置ZLen(i)

            If TargetLen(i) = 0 Then
                StrLen(i) = ZLen(i) - ALen(i) - Len(StrA(i))            '长度不确定由（结束-开始-开始长）决定
            Else
                StrLen(i) = TargetLen(i)                                '长度确定由字符串TargetLen(i)长度固定
            End If
            'MsgBox(Str(ALen(i)) + " " + Str(ZLen(i)) + " " + Str(StrLen(i)))

            If ALen(i) = 0 And ZLen(i) = 0 Then
                MsgBox("开始字符" + Str(i) + "未搜到，结束字符" + Str(i) + "未搜到")
            ElseIf ALen(i) = 0 Then
                MsgBox("开始字符" + Str(i) + "未搜到")
            ElseIf ZLen(i) = 0 Then
                MsgBox("结束字符" + Str(i) + "未搜到")
            Else
                DataBuff(i) = Trim(Mid(TextBuffdText, ALen(i) + Len(StrA(i)), StrLen(i))) '得到需要的字符串StrA(i)
            End If
        Next i
        '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        '1.搜索(订单编号、成交时间、卖家名称信息)
        '1.2由于文件头信息只出现一次, 所以先删除已检索的文本
        '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        TextSubdText = Mid(TextBuffdText, InStr(TextBuffdText, _
                       DeleteFlag(0)) + Len(DeleteFlag(0)), _
                       Len(TextBuffdText) - InStr(TextBuffdText, DeleteFlag(0)))

        'TextBoxOut.Text = TextSubdText



        '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        '2.搜索(商品名称信息)
        '2.2(商品名称信息)独立上面文本搜索
        '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        For i = 4 To 4
            StrA(i) = ""                                                             '开始字符StrA(i)
            ALen(i) = InStr(TextSubdText, StrA(i))                                   '开始位置ALen(i)
            StrZ(i) = TargetOldFlag(i + 1)                                           '结束字符StrZ(i)
            ZLen(i) = InStr(ALen(i) + Len(StrA(i)), TextSubdText, StrZ(i))           '在开始字符StrA(i)后才出现的结束位置ZLen(i)
            If TargetLen(i) = 0 Then
                StrLen(i) = ZLen(i) - ALen(i) - Len(StrA(i))                         '长度不确定由（结束-开始-开始长）决定
            Else
                StrLen(i) = TargetLen(i)                                             '长度确定由字符串TargetLen(i)长度固定
            End If
            'MsgBox(Str(i) + Str(ALen(i)) + " " + Str(ZLen(i)) + " " + Str(StrLen(i)))

            If ALen(i) = 0 And ZLen(i) = 0 Then
                MsgBox("开始字符" + Str(i) + "未搜到，结束字符" + Str(i) + "未搜到")
            ElseIf ALen(i) = 0 Then
                MsgBox("开始字符" + Str(i) + "未搜到")
            ElseIf ZLen(i) = 0 Then
                MsgBox("结束字符" + Str(i) + "未搜到")
            Else
                DataBuff(i) = Trim(Mid(TextSubdText, ALen(i) + Len(StrA(i)), StrLen(i))) '得到需要的字符串StrA(i)
            End If
        Next i



        '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        '3搜索（商品价格、商品数量和商品总价信息）
        '3.1由于“商品名称”可能影响之后判断，先删除已检索的文本后再判断
        '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        TextSubdText = Mid(TextSubdText, InStr(TextSubdText, TargetOldFlag(5)) + Len(TargetOldFlag(5)), Len(TextSubdText) - InStr(TextSubdText, TargetOldFlag(5)))
        '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        '3搜索（商品价格、商品数量和商品总价信息）
        '3.2由于“商品名称”信息出现后，紧接着的附加信息（可能出现，可能不出现）根据判断结果，选择性删除附加信息文本
        '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        While Asc(TextSubdText(0)) < Asc("0")
            TextSubdText = Mid(TextSubdText, InStr(TextSubdText, TargetOldFlag(5)) + Len(TargetOldFlag(5)), Len(TextSubdText) - InStr(TextSubdText, TargetOldFlag(5)))
            'TextBoxOut.Text = TextSubdText
        End While
        '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        '3搜索（商品价格、商品数量和商品总价信息）
        '3.3（商品价格、商品数量和商品总价信息）独立上面文本搜索
        '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        For i = 5 To 7
            StrA(i) = TargetOldFlag(i)                                               '开始字符StrA(i)
            StrA(5) = TextSubdText(0)
            ALen(i) = InStr(TextSubdText, StrA(i))                                   '开始位置ALen(i)
            StrZ(i) = TargetOldFlag(i + 1)                                           '结束字符StrZ(i)
            ZLen(i) = InStr(ALen(i) + Len(StrA(i)), TextSubdText, StrZ(i)) '在开始字符StrA(i)后才出现的结束位置ZLen(i)
            StrLen(i) = ZLen(i) - ALen(i) - Len(StrA(i))                             '长度不确定由（结束-开始-开始长）决定
            'MsgBox(Str(i) + Str(ALen(i)) + " " + Str(ZLen(i)) + " " + Str(StrLen(i)))
            If ALen(i) = 0 And ZLen(i) = 0 Then
                MsgBox("开始字符" + Str(i) + "未搜到，结束字符" + Str(i) + "未搜到")
            ElseIf ALen(i) = 0 Then
                MsgBox("开始字符" + Str(i) + "未搜到")
            ElseIf ZLen(i) = 0 Then
                MsgBox("结束字符" + Str(i) + "未搜到")
            Else
                StrA(5) = ""
                StrLen(5) = StrLen(5) + 1
                DataBuff(i) = Trim(Mid(TextSubdText, ALen(i) + Len(StrA(i)), StrLen(i))) '得到需要的字符串StrA(i)
            End If
        Next i



        '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        '4搜索（运输费用、保险费用信息）
        '4.1由于（运输费用、保险费用信息）出现可不出现，独立上面文本搜索（文本源为裁剪后文本）
        '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        For i As Integer = 8 To 8
            StrA(i) = TargetOldFlag(i)                                              '开始字符StrA(i)
            ALen(i) = InStr(TextSubdText, StrA(i))                                  '开始位置ALen(i)
            StrZ(i) = TargetOldFlag(i + 1)                                          '结束字符StrZ(i)
            ZLen(i) = InStr(ALen(i) + Len(StrA(i)), TextSubdText, StrZ(i))          '在开始字符StrA(i)后才出现的结束位置ZLen(i)
            StrZ(i + 1) = TargetOldFlag(i + 2)                                      '结束字符StrZ(i)
            ZLen(i + 1) = InStr(ALen(i) + Len(StrA(i)), TextSubdText, StrZ(i + 1))  '在开始字符ZLen(i)后才出现的结束位置ZLen(i+1)
            If ALen(i) = 0 Then
                MsgBox("开始字符" + Str(i) + "未搜到,没有后话")
            ElseIf ZLen(i) = 0 And ZLen(i + 1) = 0 Then
                DataBuff(i) = "出错"
                DataBuff(i + 1) = "出错"
                MsgBox("结束字符" + Str(i) + "未搜到，结束字符" + Str(i + 1) + "未搜到")
                'MsgBox(ALen(i))
            ElseIf ZLen(i) = 0 Then
                StrLen(i) = ZLen(i + 1) - ALen(i) - Len(StrA(i))                     '长度不确定由（结束2-开始-开始长）决定
                'MsgBox(Str(ALen(i) + Len(StrA(i))) + "" + Str(ZLen(i + 1)) + " " + Str(StrLen(i)))
                DataBuff(i) = Trim(Mid(TextSubdText, ALen(i) + Len(StrA(i)), StrLen(i)))
                DataBuff(i + 1) = "0"
                'MsgBox("仅结束字符" + Str(i) + "未搜到")
            ElseIf ZLen(i + 1) = 0 Then
                DataBuff(i) = "出错"
                DataBuff(i + 1) = "0"
                MsgBox("仅结束字符" + Str(i + 1) + "未搜到")
            Else
                StrLen(i) = ZLen(i) - ALen(i) - Len(StrA(i))                          '长度不确定由（结束1-开始-开始长）决定
                DataBuff(i) = Trim(Mid(TextSubdText, ALen(i) + Len(StrA(i)), StrLen(i)))
                StrLen(i + 1) = ZLen(i + 1) - ZLen(i) - Len(StrZ(i))                  '长度不确定由（结束2-结束1-开始长）决定
                DataBuff(i + 1) = Trim(Mid(TextSubdText, ZLen(i) + Len(StrZ(i)), StrLen(i + 1)))
                'MsgBox(Str(ALen(i)) + " " + Str(ZLen(i)) + " " + Str(ZLen(i + 1)) + " " + Str(StrLen(i)) + " " + Str(StrLen(i + 1)))
            End If

        Next



        '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        '4搜索（运输费用、保险费用信息）
        '4.2假如包含"卖家包邮""虚拟物品"等字眼，运输费用=0保险费用=0
        '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        If InStr(TextBuffdText, "卖家包邮") <> 0 Or InStr(TextBuffdText, "虚拟物品") <> 0 Then
            DataBuff(8) = "0"
            DataBuff(9) = "0"
        End If

        ButtonData1_Click()
        ButtonData2_Click()
        ButtonData3_Click()
        ButtonData4_Click()
        ButtonData5_Click()
        ButtonData6_Click()
        ButtonData7_Click()
        ButtonData8_Click()



        '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        '5第二轮搜索
        '5.1重复搜索商品名称、商品价格、商品数量和商品总价信息
        '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        Dim ss As String = DeleteFlag(1)
        Dim ssp As Integer = InStr(TextSubdText, ss)                        '开始位置s9
        TextSubdText = Mid(TextSubdText, ssp + Len(ss), Len(TextSubdText) - ssp)
        Dim Cnt As Integer
        While ssp <> 0
            Cnt = Cnt + 1
            For i = 4 To 4
                StrA(i) = TargetOldFlag(i)                                               '开始字符StrA(i)
                StrA(4) = TextSubdText(0)
                ALen(i) = InStr(TextSubdText, StrA(i))                                   '开始位置ALen(i)
                StrZ(i) = TargetOldFlag(i + 1)                                           '结束字符StrZ(i)
                'ZLen(i) = InStr(TextBuffdText, StrZ(i))                                 '结束位置ZLen(i)
                ZLen(i) = InStr(ALen(i) + Len(StrA(i)), TextSubdText, StrZ(i))           '在开始字符StrA(i)后才出现的结束位置ZLen(i)

                If TargetLen(i) = 0 Then
                    StrLen(i) = ZLen(i) - ALen(i) - Len(StrA(i))                         '长度不确定由（结束-开始-开始长）决定
                Else
                    StrLen(i) = TargetLen(i)                                             '长度确定由字符串TargetLen(i)长度固定
                End If
                'MsgBox(Str(i) + Str(ALen(i)) + " " + Str(ZLen(i)) + " " + Str(StrLen(i)))

                If ALen(i) = 0 And ZLen(i) = 0 Then
                    MsgBox("开始字符" + Str(i) + "未搜到，结束字符" + Str(i) + "未搜到")
                ElseIf ALen(i) = 0 Then
                    MsgBox("开始字符" + Str(i) + "未搜到")
                ElseIf ZLen(i) = 0 Then
                    MsgBox("结束字符" + Str(i) + "未搜到")
                Else
                    StrA(4) = ""
                    StrLen(5) = StrLen(4) + 1
                    TextBoxArray(i - 1 + 8 * Cnt).Text = Replace(Trim(Mid(TextSubdText, ALen(i) + Len(StrA(i)), StrLen(i))), Chr(10), "")  '得到需要的字符串si
                End If
            Next i

            TextSubdText = Mid(TextSubdText, InStr(TextSubdText, TargetOldFlag(5)) + Len(TargetOldFlag(5)), Len(TextSubdText) - InStr(TextSubdText, TargetOldFlag(5)))
            While Asc(TextSubdText(0)) < Asc("0")
                TextSubdText = Mid(TextSubdText, InStr(TextSubdText, TargetOldFlag(5)) + Len(TargetOldFlag(5)), Len(TextSubdText) - InStr(TextSubdText, TargetOldFlag(5)))
                'TextBoxOut.Text = TextSubdText
            End While

            TargetOldFlag(8) = TargetOldFlag(11)
            For i = 5 To 7
                StrA(i) = TargetOldFlag(i)                                               '开始字符StrA(i)
                StrA(5) = TextSubdText(0)
                ALen(i) = InStr(TextSubdText, StrA(i))                                   '开始位置ALen(i)
                StrZ(i) = TargetOldFlag(i + 1)                                           '结束字符StrZ(i)
                'ZLen(i) = InStr(TextBuffdText, StrZ(i))                                 '结束位置ZLen(i)
                ZLen(i) = InStr(ALen(i) + Len(StrA(i)), TextSubdText, StrZ(i))           '在开始字符StrA(i)后才出现的结束位置ZLen(i)
                StrLen(i) = ZLen(i) - ALen(i) - Len(StrA(i))                             '长度不确定由（结束-开始-开始长）决定
                'MsgBox(Str(i) + Str(ALen(i)) + " " + Str(ZLen(i)) + " " + Str(StrLen(i)))
                If ALen(i) = 0 And ZLen(i) = 0 Then
                    MsgBox("开始字符" + Str(i) + "未搜到，结束字符" + Str(i) + "未搜到")
                ElseIf ALen(i) = 0 Then
                    MsgBox("开始字符" + Str(i) + "未搜到")
                ElseIf ZLen(i) = 0 Then
                    MsgBox("结束字符" + Str(i) + "未搜到")
                Else
                    StrA(5) = ""
                    StrLen(5) = StrLen(5) + 1
                    TextBoxArray(i - 1 + 8 * Cnt).Text = Replace(Trim(Mid(TextSubdText, ALen(i) + Len(StrA(i)), StrLen(i))), Chr(10), "")  '得到需要的字符串si
                End If
            Next i
            '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            '5第二轮搜索
            '5.2(订单编号、成交时间、卖家名称、运输费用、保险费用信息Copy上面)
            '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            TextBoxArray(0 + 8 * Cnt).Text = TextBoxArray(0).Text
            TextBoxArray(1 + 8 * Cnt).Text = TextBoxArray(1).Text
            TextBoxArray(2 + 8 * Cnt).Text = TextBoxArray(2).Text
            TextBoxArray(6 + 8 * Cnt).Text = TextBoxArray(6).Text
            TextBoxArray(7 + 8 * Cnt).Text = TextBoxArray(7).Text

            'TextBoxOut.Text = TextSubdText
            ssp = InStr(TextSubdText, ss)
            TextSubdText = Mid(TextSubdText, ssp + Len(ss), Len(TextSubdText) - ssp)


        End While
        For Each btn As TextBox In TextBoxArray
            TextBoxOut.Text = TextBoxOut.Text + btn.Text + Chr(10)
        Next
    End Sub

    Private Sub ButtonData1_Click() Handles ButtonData1.Click
        TextBoxList01.Text = DataBuff(1)
    End Sub

    Private Sub ButtonData2_Click() Handles ButtonData2.Click
        TextBoxList02.Text = DataBuff(2)
    End Sub

    Private Sub ButtonData3_Click() Handles ButtonData3.Click
        TextBoxList03.Text = DataBuff(3)
    End Sub

    Private Sub ButtonData4_Click() Handles ButtonData4.Click
        TextBoxList04.Text = DataBuff(4)
    End Sub

    Private Sub ButtonData5_Click() Handles ButtonData5.Click
        TextBoxList05.Text = DataBuff(5)
    End Sub

    Private Sub ButtonData6_Click() Handles ButtonData6.Click
        TextBoxList06.Text = DataBuff(6)
    End Sub

    Private Sub ButtonData7_Click() Handles ButtonData7.Click
        TextBoxList07.Text = DataBuff(8)
    End Sub

    Private Sub ButtonData8_Click() Handles ButtonData8.Click
        TextBoxList08.Text = DataBuff(9)
    End Sub

    Private Sub ComboBoxFileStyle_SelectionChanged(ByVal sender As System.Object, ByVal e As System.Windows.Controls.SelectionChangedEventArgs) Handles ComboBoxFileStyle.SelectionChanged
        If ComboBoxFileStyle.SelectedIndex = 1 Then
            Button2Excel.Background = New SolidColorBrush(Color.FromArgb(255, 255, 0, 0))
            Button2Excel.Content = "Excel2003"
        Else
            Button2Excel.Background = New SolidColorBrush(Color.FromArgb(255, 0, 255, 0))
            Button2Excel.Content = "Excel2007"
        End If
    End Sub

    Private Sub Button2Excel_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button2Excel.Click
        TextBoxOut.Text = ""
        Dim oExcel As New Excel.Application
        Dim obook As Excel.Workbook
        Dim oSheet As Excel.Worksheet
        Dim DataArray(2000, 2000) As String

        obook = oExcel.Workbooks.Add()
        oSheet = obook.Sheets(1)

        oSheet.Name = "ok"

        TextBoxOut.Text = ""


        For i As Integer = 1 To 64
            DataArray(i, 1) = TextBoxArray(i - 1).Text
            TextBoxOut.Text = TextBoxOut.Text + Chr(10) + DataArray(i, 1)
            oSheet.Cells(i, 1) = DataArray(i, 1)
        Next

        oSheet.SaveAs("c:\4.xls")
        obook.Save()
        oSheet = Nothing
        obook.Close()
        obook = Nothing
        oExcel.Quit()
        oExcel = Nothing

    End Sub

    Private Sub Button3Excel_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button3Excel.Click
        Dim exapp As Excel.Application  '定义excel应用程序
        Dim exbook As Excel.Workbook    '定义工作簿
        Dim exsheet As Excel.Worksheet  '定义工作表
        Dim exrange As Excel.Range      '定义工作区域
        'exapp.Visible = True                                 '显示excel 程序
        'exbook = exapp.Workbooks.Add()                       '添加新工作簿　　
        'exbook = exapp.Workbooks.Open("薄名")                '打开已在工作薄
        'exsheet = exbook.Sheets(n)                           '获得第n个工作表的控制句柄,后面就由它处理了
        'exsheet.Cells(row, col) = 值                         '对指定单元格赋值,这个操作大量出现哦

        'exsheet.Range(cells, cells).font()                   '这个属性也常用到，设置格式就是它了:
        'exsheet.Range(cells, cells).font.colorindex = 3      '设置颜色
        'exsheet.Range(cells, cells).Borders.LineStyle = 1    '设边框线
        'exsheet.Range(cells, cells).EntireColumn.AutoFit()   '自动列宽　 /可以改为自动行高哦
        'exsheet.Range(cells, cells).merge()                  '合并单元格,复杂的表格这个也用的多哦
        'exsheet.Range(cells, cells).HorizontalAlignment = 3  '水平居中　 ,当然也可以改为垂直的
        'exsheet.PageSetup.Orientation = 2                    '页面横向

        'exsheet.SaveAs("文件名")
        'exbook.Save()

        'exsheet = Nothing
        'exbook.Close()
        'exbook = Nothing
        'exapp.Quit()
        'exapp = Nothing

    End Sub

End Class

Public Class TimeRegex
    Private hour As Integer = 0
    Private minute As Integer = 0
    Private second As Integer = 0
    Private totalTime As Integer = 0
    Private exp As String '时间表达式
    Sub New()
    End Sub
    '根据时间文本解析出其中的数字部分
    Private Function getTime(ByVal timeKind As String) As String
        Dim timeMatch As Match
        Dim time As String
        '先从中解析出包含数字和中文的部分
        timeMatch = Regex.Match(exp, timeKind)
        If timeMatch.Success = True Then
            time = timeMatch.Value
            '然后从得到的文本中解析出数字
            Return Regex.Match(time, "[0-9]+").Value
        Else
            Return "0"
        End If
    End Function

    '根据传入的表达式计算总时间
    Public Function getTotalTime(ByVal _exp As String) As Integer
        exp = _exp
        '分别计算出小时，分钟，秒，然后得到总时间
        hour = Integer.Parse(getTime("[0-9]+小时"))
        minute = Integer.Parse(getTime("[0-9]+分钟"))
        second = Integer.Parse(getTime("[0-9]+秒"))
        totalTime = hour * 3600 + minute * 60 + second
        Return totalTime
    End Function
End Class

'Form1类代码如下：
'Public Class Form1
'Inherits System.Windows.Forms.Form
'Private regex As New TimeRegex
'Windows窗体设计器生成代码省略
'    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click SecondTime.Text = regex.getTotalTime(timeExp.Text).ToString & "秒"
'End Sub
'End Class